#include "Brightness.h"

#include <Arduino.h>

// 将整数转换为Brightness类型
Brightness getBrightness(int value) {
    if (value < 100) {  // LED灭 0~99 -> 0
        return OFF;
    } else if (value <= 130) {  // LED一级亮度 99~130 -> 100
        return LEVEL_1;
    } else if (value <= 170) {  // LED二级亮度 131~170 -> 150
        return LEVEL_2;
    } else if (value <= 210) {  // LED三级亮度 171~210 -> 200
        return LEVEL_3;
    } else {  // LED全亮 211~255 -> 255
        return FULL_BRIGHT;
    }
}

// 将Brightness的值转换为字符串
const char* brightnessToStr(Brightness brightness) {
    static char buffer[4];
    sprintf(buffer, "%d", brightness);
    return buffer;
}